from flask import Blueprint, redirect

admin_bp = Blueprint("admin_bp", __name__, url_prefix='/admin')

from .views import *


@admin_bp.before_request
def before_request():
    """拦截普通用户进入后台管理首页"""
    if not request.url.endswith(url_for("admin_bp.admin_login")):
        user_id = session.get("user_id", None)
        is_admin = session.get('is_admin', None)
        if not (user_id and is_admin):
            return redirect("/")
